package com.itlong.cloud.commons.wechat.resource;

import com.itlong.cloud.POJO.VO.app.AppPayParkFeeNoticeVO;
import com.itlong.cloud.paymenthub.IWeChatPayServiceClient;
import com.itlong.cloud.commons.wechat.service.IWeChatPayService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Map;

/**
 * <desc>
 * 演示App微信支付暴露接口
 * </desc>
 *
 * @createDate 2018/4/23
 */
@RestController
public class WeChatPayServiceResource implements IWeChatPayServiceClient {

    @Autowired
    private IWeChatPayService iWechatPayService;

    /**
     * <desc>
     *      调微信后台统一下单接口/商户后台保存订单
     * <desc/>
     *
     * @param  total 支付金额
     * @param billsId 账单编号
     * @param feeType 缴费类型 1物业费 2维修费 3临时车缴费 4月卡缴费
     * @param openId 公众号支付需要用此参数，用户在公众号中的唯一标识
     * @param payType 支付类型 2app支付 3小程序支付 4公众号支付 5h5支付
     * @param deviceUnique 设备编号
     * @param deviceUnique 设备编号
     * @param times 次数
     * @param amount 金额
     * @return
     * @author Juguang.S
     * @createDate 2018/4/23
     */
    @Override
    @PostMapping(path = "/pay/saveOrder")
    public Map<Object,Object> saveOrder(@RequestParam("total") String total,
                                        @RequestParam("loginUserId") String loginUserId,
                                        @RequestParam("billsId") String billsId,
                                        @RequestParam("feeType") String feeType,
                                        @RequestParam(value = "openId",required = false) String openId,
                                        @RequestParam(value = "payType",required = false) Integer payType,
                                        @RequestParam(value = "deviceUnique",required = false) String deviceUnique,
                                        @RequestParam(value = "roomId",required = false) String roomId,
                                        @RequestParam(value = "ip",required = false) String ip,
                                        @RequestParam(value = "times",required = false) String times,
                                        @RequestParam(value = "amount",required = false) String amount
    ) {
        return iWechatPayService.saveOrder(total,loginUserId,billsId,feeType,openId,payType,deviceUnique,roomId,ip,times,amount);
    }

    /**
     * <desc>
     *      微信支付结果回调通知
     * <desc/>
     * @param
     * @return
     * @author Juguang.S
     * @createDate 2018/4/25
     */
    @Override
    @PostMapping(path = "/pay/payResultNotice")
    public AppPayParkFeeNoticeVO payResultNotice(@RequestParam("rturnInfo") String rturnInfo) {
        return iWechatPayService.payResultNotice(rturnInfo);
    }

    /**
     * <desc>
     *      演示版微信支付结果回调通知
     * <desc/>
     * @param
     * @return
     * @author Juguang.S
     * @createDate 2018/8/29
     */
    @Override
    @PostMapping(path = "/pay/showPayResultNotice")
    public String showPayResultNotice(@RequestParam("rturnInfo") String rturnInfo) {
        return iWechatPayService.showPayResultNotice(rturnInfo);
    }

    /**
     * <desc>
     *      根据商户订单号查询订单
     * <desc/>
     * @param  tradeId  商户订单号
     * @return
     * @author Juguang.S
     * @createDate 2018/4/25
     */
    @Override
    @PostMapping(path = "/pay/getOrderBytradeId")
    public Map<String,Object> getOrderBytradeId(@RequestParam("tradeId") String tradeId) {
        return iWechatPayService.getOrderBytradeId(tradeId);
    }

    /**
     * <desc>
     *      定时任务获取前一天的微信对账单
     * <desc/>
     * @param
     * @return
     * @author Juguang.S
     * @createDate 2018/8/28
     */
    @Override
    @PostMapping(path = "/pay/downloadWechatBill")
    public void downloadWechatBill() throws Exception{
        iWechatPayService.downloadWechatBill();
    }

    /**
     * <desc>
     *      查询第三方支付管理微信支付是否被禁用
     * <desc/>
     * @param thirdPayType 1微信支付 2银联转账
     * @return
     * @author Juguang.S
     * @createDate 2018/9/26
     */
    @Override
    @PostMapping(path = "/pay/getThirdPayStatus")
    public Integer getThirdPayStatus(@RequestParam("thirdPayType") Integer thirdPayType) {
        return iWechatPayService.getThirdPayStatus(thirdPayType);
    }


    /**
     * <desc>
     *      查询该账单是否已被支付
     * <desc/>
     * @param billsId 账单编号
     * @return
     * @author Juguang.S
     * @createDate 2018/10/09
     */
    @Override
    @PostMapping(path = "/pay/getBillStatus")
    public Integer getBillStatus(@RequestParam("billsId") String billsId) {
        return iWechatPayService.getBillStatus(billsId);
    }

    /**
     * <desc>
     *      保存停车场错误指令
     * <desc/>
     * @param projectId 项目编号
     * @param requestContent 请求内容
     * @return
     * @author Juguang.S
     * @createDate 2018/11/15
     */
    @PostMapping(path = "/pay/sendMessager")
    public void sendMessager(@RequestParam("projectId") String projectId,@RequestParam("requestContent") String requestContent,@RequestParam("payType") Integer payType) throws Exception{
        iWechatPayService.sendMessager(projectId,requestContent,payType);
    }

    /**
     * <desc>
     *      处理零元支付情况通知富士
     * </desc>
     *
     * @param billsId 账单ID
     * @return 缴费记录
     * @author Juguang.S
     * @createDate 2018/12/13
     */
    @RequestMapping(path = "/pay/getZeroPaymentNotice",method = RequestMethod.POST)
    public AppPayParkFeeNoticeVO getZeroPaymentNotice(@RequestParam("billsId") String billsId) throws Exception{
        return iWechatPayService.getZeroPaymentNotice(billsId);
    }

    /**
     * <desc>
     *      查询账单的金额
     * <desc/>
     * @param billsId 账单编号
     * @param type 支付类型 1代表除云服务费外的缴费 2代表云服务费的缴费
     * @return
     * @author Juguang.S
     * @createDate 2019/09/17
     */
    @PostMapping(path = "/pay/getBillTotal")
    public String getBillTotal(@RequestParam("billsId") String billsId, @RequestParam("type") Integer type){
        return iWechatPayService.getBillTotal(billsId,type);
    }
}